package BQ;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.PriorityBlockingQueue;

public class Test {
    public static void main(String[] args) {
        BlockingQueue<Integer> blockingQueue = new ArrayBlockingQueue<>(10000);
        Thread thread1 = new Thread(() -> {
            int num = 0;
            while (true) {
                try {
                    blockingQueue.put(num);
                    System.out.println("生产了："+num);
                    num++;
                    //Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        Thread thread2 = new Thread(() -> {
            while (true) {
                int num;
                try {
                    num = blockingQueue.take();
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("消费了：" + num);
            }
        });
        thread1.start();
        thread2.start();
        //BlockingQueue<String> blockingQueue = new LinkedBlockingQueue<>();
        //BlockingQueue<String> blockingQueue = new PriorityBlockingQueue<>();
    }
}
